using DataDynamics.ActiveReports;
using DataDynamics.ActiveReports.Export.Xls;
using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
using TVSBH.func;
namespace TVSGPP.func
{
	public class frmRepProvider : Form
	{
		private IContainer components = null;
		private Button btnPrint;
		private Button btnClose;
		private DataGridView dgvList;
		private DataGridViewTextBoxColumn Column7;
		private DataGridViewTextBoxColumn Column2;
		private DataGridViewTextBoxColumn Column1;
		private Button btnExportToExcel;
		private Func objFunc = new Func();
		private DataTable objTable = new DataTable();
		private string strConnection = "";
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			this.btnPrint = new Button();
			this.btnClose = new Button();
			this.dgvList = new DataGridView();
			this.Column7 = new DataGridViewTextBoxColumn();
			this.Column2 = new DataGridViewTextBoxColumn();
			this.Column1 = new DataGridViewTextBoxColumn();
			this.btnExportToExcel = new Button();
			((ISupportInitialize)this.dgvList).BeginInit();
			base.SuspendLayout();
			this.btnPrint.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnPrint.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnPrint.Location = new Point(7, 564);
			this.btnPrint.Name = "btnPrint";
			this.btnPrint.Size = new Size(102, 30);
			this.btnPrint.TabIndex = 47;
			this.btnPrint.Text = "Xem và in [ F7 ]";
			this.btnPrint.UseVisualStyleBackColor = true;
			this.btnPrint.Click += new EventHandler(this.btnPrint_Click);
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(794, 564);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(100, 30);
			this.btnClose.TabIndex = 46;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.dgvList.AllowUserToAddRows = false;
			this.dgvList.AllowUserToDeleteRows = false;
			this.dgvList.AllowUserToOrderColumns = true;
			this.dgvList.AllowUserToResizeColumns = false;
			this.dgvList.AllowUserToResizeRows = false;
			dataGridViewCellStyle.BackColor = Color.FromArgb(192, 255, 255);
			dataGridViewCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvList.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvList.BackgroundColor = Color.White;
			this.dgvList.BorderStyle = BorderStyle.Fixed3D;
			this.dgvList.ColumnHeadersHeight = 26;
			this.dgvList.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvList.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Column7,
				this.Column2,
				this.Column1
			});
			this.dgvList.Cursor = Cursors.Hand;
			this.dgvList.EnableHeadersVisualStyles = false;
			this.dgvList.Location = new Point(7, 12);
			this.dgvList.MultiSelect = false;
			this.dgvList.Name = "dgvList";
			this.dgvList.ReadOnly = true;
			this.dgvList.RowHeadersVisible = false;
			this.dgvList.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvList.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.dgvList.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvList.Size = new Size(886, 546);
			this.dgvList.TabIndex = 49;
			this.Column7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column7.DataPropertyName = "Name";
			dataGridViewCellStyle2.NullValue = null;
			this.Column7.DefaultCellStyle = dataGridViewCellStyle2;
			this.Column7.HeaderText = "Tên Nhà cung cấp";
			this.Column7.MinimumWidth = 400;
			this.Column7.Name = "Column7";
			this.Column7.ReadOnly = true;
			this.Column7.Width = 400;
			this.Column2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Column2.DataPropertyName = "Address";
			this.Column2.HeaderText = "Địa chỉ";
			this.Column2.MinimumWidth = 120;
			this.Column2.Name = "Column2";
			this.Column2.ReadOnly = true;
			this.Column1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column1.DataPropertyName = "Phone";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleLeft;
			dataGridViewCellStyle3.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			this.Column1.DefaultCellStyle = dataGridViewCellStyle3;
			this.Column1.HeaderText = "Số điện thoại";
			this.Column1.MinimumWidth = 150;
			this.Column1.Name = "Column1";
			this.Column1.ReadOnly = true;
			this.Column1.Width = 150;
			this.btnExportToExcel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left);
			this.btnExportToExcel.Enabled = false;
			this.btnExportToExcel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnExportToExcel.Location = new Point(109, 564);
			this.btnExportToExcel.Name = "btnExportToExcel";
			this.btnExportToExcel.Size = new Size(102, 30);
			this.btnExportToExcel.TabIndex = 50;
			this.btnExportToExcel.Text = "Xuất File Excel";
			this.btnExportToExcel.UseVisualStyleBackColor = true;
			this.btnExportToExcel.Click += new EventHandler(this.btnExportToExcel_Click);
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.btnExportToExcel);
			base.Controls.Add(this.dgvList);
			base.Controls.Add(this.btnPrint);
			base.Controls.Add(this.btnClose);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 0);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.Name = "frmRepProvider";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "SỔ THEO DÕI NHÀ PHÂN PHỐI";
			base.WindowState = FormWindowState.Maximized;
			base.Load += new EventHandler(this.frmRepGroupProduct_Load);
			base.KeyDown += new KeyEventHandler(this.frmRepGroupProduct_KeyDown);
			((ISupportInitialize)this.dgvList).EndInit();
			base.ResumeLayout(false);
		}
		public frmRepProvider()
		{
			Program.strConnectionString = this.objFunc.strConnectionString;
			this.InitializeComponent();
		}
		public void getData()
		{
			this.dgvList.AutoGenerateColumns = false;
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			string cmdText = "SELECT ProID, Name, Address, Phone FROM [TabPartner] WHERE [IsProvider] = 1 ORDER BY [Name]";
			SqlCommand selectCommand = new SqlCommand(cmdText, sqlConnection);
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
			DataSet dataSet = new DataSet();
			sqlConnection.Open();
			sqlDataAdapter.Fill(dataSet);
			this.dgvList.DataSource = dataSet.Tables[0];
			this.objTable = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
			sqlDataAdapter.Dispose();
			dataSet.Dispose();
			if (this.objTable.Rows.Count > 0)
			{
				this.btnPrint.Enabled = true;
				this.btnExportToExcel.Enabled = true;
			}
			else
			{
				this.btnPrint.Enabled = false;
				this.btnExportToExcel.Enabled = false;
			}
		}
		private void frmRepGroupProduct_Load(object sender, EventArgs e)
		{
			this.getData();
		}
		private void frmRepGroupProduct_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.F7)
			{
				this.btnPrint.PerformClick();
			}
			else
			{
				if (e.KeyCode == Keys.Escape)
				{
					base.Close();
				}
			}
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void btnPrint_Click(object sender, EventArgs e)
		{
			frmRepProviderPrintView frmRepProviderPrintView = new frmRepProviderPrintView();
			frmRepProviderPrint.objTable = this.objTable;
			frmRepProviderPrint.typeRep = "0";
			frmRepProviderPrintView.ShowDialog();
		}
		private void btnExportToExcel_Click(object sender, EventArgs e)
		{
			try
			{
				frmRepProviderPrint.objTable = new DataTable();
				frmRepProviderPrint.objTable = this.objTable;
				ActiveReport3 activeReport = new frmRepProviderPrint();
				activeReport.Run();
				XlsExport xlsExport = new XlsExport();
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.ShowDialog();
				string text = saveFileDialog.FileName;
				if (text != "")
				{
					if (!text.ToUpper().Contains(".XLS"))
					{
						text += ".xls";
					}
					xlsExport.MinRowHeight = 0f;
					xlsExport.UseCellMerging = true;
					xlsExport.Export(activeReport.Document, text);
					MessageBox.Show("Hệ thống đã hoàn thành việc xuất dữ liệu ra file Excel", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				else
				{
					MessageBox.Show("Bạn chưa chọn đường dẫn và tên file cần xuất!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
				}
			}
			catch
			{
			}
		}
	}
}
